package com.hefei.rdd

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * @author caizhengjun
 * @date 2020/8/28 7:01 下午
 */
object Spark07_RDD_Cache {

  def main(args: Array[String]): Unit = {

    val conf: SparkConf = new SparkConf().setMaster("local[*]").setAppName(this.getClass.getSimpleName)

    val sc: SparkContext = new SparkContext(conf)
    sc.setCheckpointDir("checkpoint")

    val list: List[Int] = List(1, 2, 3, 4)

    val rdd: RDD[Int] = sc.makeRDD(list)

    val mapRDD: RDD[(Int, Int)] = rdd.map(num => {
      println("map...")
      (num, 1)
    })

    //mapRDD.cache()
    mapRDD.checkpoint()
    println(mapRDD.toDebugString)
    println(mapRDD.collect().mkString(","))
    println(mapRDD.toDebugString)
    println(mapRDD.collect().mkString("&"))

    sc.stop()
  }
}
